<?php
namespace app\manager\controller;

class CarTpl extends BaseController
{
    protected $check_auths = false; 
    /**
     * GET shwo carcate info list
     * @return [type] [description]
     */
    public function index()
    {
        $list = model('CarTpls')->getCarTplLists();
        $this->assign('list',$list);
        return view('p/cartpl/index');
    }
    /**
     * GET show carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function read($id)
    {
        echo "string";
    }

    /**
     * GET shwo create carcate info
     * @return [type] [description]
     */
    public function create()
    {
        //营地表
        $camps= model('Camps')->getCampList();
        $this->assign('camps',$camps);
        //品牌表
        $brands = model('CarBrands')->getCarBrandsLists();
        $this->assign('brand',$brands);
        //车类型/国别/燃油/准驾类型配置文件
        $carcates=model('CarCates')->getCarCateList();
        $carcates = array_column($carcates, 'name', 'id');
        $this->assign('carcates',$carcates);
        //国别
        $country=model('CarCountries')->getCountriesList();
        $country = array_column($country, 'name', 'id');
        $this->assign('country',$country);
        //准驾类型
        $drive_type=model('DriverTypes')->getDriverTypesLists();
        $drive_type = array_column($drive_type, 'name', 'id');
        $this->assign('drive_type',$drive_type);
        //车系字段表
        $ziduans=model('Caravans')->getZiduna();
        $this->assign('ziduans',$ziduans);
        return view('p/cartpl/create');
    }
    /**
     * POST create new carcate info
     * @return [type] [description]
     */
    public function save()
    {
        $post_cartpl_info['cartpl_name'] = input('post.cartpl_name');
        $post_cartpl_info['describe'] = input('post.describe');
        $post_cartpl_info['carcate_id'] = input('post.carcate_id');
        $post_cartpl_info['brand_id'] = input('post.brand_id');
        $post_cartpl_info['grade'] = input('post.grade');
        $post_cartpl_info['carcountry_id'] = input('post.carcountry_id');
        $post_cartpl_info['drivetype_id'] = input('post.drivetype_id');
        $post_cartpl_info['park'] = input('post.park');
        $post_cartpl_info['single_bed_num'] = input('post.single_bed_num');
        $post_cartpl_info['double_bed_num'] = input('post.double_bed_num');
        $post_cartpl_info['sofe_num'] = input('post.sofe_num');
        $post_cartpl_info['people_num'] = input('post.people_num');
        $post_cartpl_info['size'] = input('post.size');
        $post_cartpl_info['register_date'] = input('post.register_date');
        $post_cartpl_info['plate_num'] = input('post.plate_num');
        $post_cartpl_info['gear'] = input('post.gear');
        $post_cartpl_info['wifi'] = input('post.wifi');
        $post_cartpl_info['kitchen'] = input('post.kitchen');
        $post_cartpl_info['bathroom'] = input('post.bathroom');
        $post_cartpl_info['tv'] = input('post.tv');
        $post_cartpl_info['washer'] = input('post.washer');
        $post_cartpl_info['air_condition'] = input('post.air_condition');
        $post_cartpl_info['the_shower'] = input('post.the_shower');
        $post_cartpl_info['extinguisher'] = input('post.extinguisher');
        $post_cartpl_info['annunciator'] = input('post.annunciator');
        $post_cartpl_info['monitored'] = input('post.monitored');
        //halt($post_cartpl_info);

        $cartpl = model('CarTpls')->createCarTpl($post_cartpl_info);

        if($cartpl){
            return $this->success('创建车系成功', '/cartpl');
        }
            return $this->error('创建失败');

    }
    /**
     * GET edit carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function edit($id)
    {
        $cartpl_info = model('CarTpls')->getCarTplInfo($id);
        $this->assign('cartpl_info',$cartpl_info);//halt($cartpl_info);
        $this->assign('id',$id);
        //营地表
        $camps= model('Camps')->getCampList();
        $this->assign('camps',$camps);
        //品牌表
        $brands = model('CarBrands')->getCarBrandsLists();
        $this->assign('brand',$brands);
        //车类型/国别/燃油/准驾类型配置文件
        $carcates=model('CarCates')->getCarCateList();
        $carcates = array_column($carcates, 'name', 'id');
        $this->assign('carcates',$carcates);
        //国别
        $country=model('CarCountries')->getCountriesList();
        $country = array_column($country, 'name', 'id');
        $this->assign('country',$country);
        //准驾类型
        $drive_type=model('DriverTypes')->getDriverTypesLists();
        $drive_type = array_column($drive_type, 'name', 'id');
        $this->assign('drive_type',$drive_type);
        //车系字段表
        $ziduans=model('Caravans')->getZiduna();
        $this->assign('ziduans',$ziduans);
        return view('p/cartpl/edit');
    }
    /**
     * PUT update carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function update($id)
    {

        $post_cartpl_info['cartpl_name'] = input('post.cartpl_name');
        $post_cartpl_info['describe'] = input('post.describe');
        $post_cartpl_info['carcate_id'] = input('post.carcate_id');
        $post_cartpl_info['brand_id'] = input('post.brand_id');
        $post_cartpl_info['grade'] = input('post.grade');
        $post_cartpl_info['carcountry_id'] = input('post.carcountry_id');
        $post_cartpl_info['drivetype_id'] = input('post.drivetype_id');
        $post_cartpl_info['park'] = input('post.park');
        $post_cartpl_info['single_bed_num'] = input('post.single_bed_num');
        $post_cartpl_info['double_bed_num'] = input('post.double_bed_num');
        $post_cartpl_info['sofe_num'] = input('post.sofe_num');
        $post_cartpl_info['people_num'] = input('post.people_num');
        $post_cartpl_info['size'] = input('post.size');
        $post_cartpl_info['register_date'] = input('post.register_date');
        $post_cartpl_info['plate_num'] = input('post.plate_num');
        $post_cartpl_info['gear'] = input('post.gear');
        $post_cartpl_info['wifi'] = input('post.wifi');
        $post_cartpl_info['kitchen'] = input('post.kitchen');
        $post_cartpl_info['bathroom'] = input('post.bathroom');
        $post_cartpl_info['tv'] = input('post.tv');
        $post_cartpl_info['washer'] = input('post.washer');
        $post_cartpl_info['air_condition'] = input('post.air_condition');
        $post_cartpl_info['the_shower'] = input('post.the_shower');
        $post_cartpl_info['extinguisher'] = input('post.extinguisher');
        $post_cartpl_info['annunciator'] = input('post.annunciator');
        $post_cartpl_info['monitored'] = input('post.monitored');
        
        $cartpl = model('CarTpls')->updateCarTpl($id, $post_cartpl_info);

        if($cartpl){
            return $this->success('更新成功', '/cartpl');
        }
            return $this->error('更新失败');

    }
    
    /**
     * DELETE carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete($id)
    {
       $ids=input('post.ids/a');
        if (empty($ids)) {
          return $this->error('请选择要删除的选项'); 
        }
        $count = model('CarTpls')->delInfo($ids);
        if ($count) {
           return $this->success('删除成功','/cartpl');
        }
        return $this->error('删除失败');
    }
    
   
}

